package com.pro.schedule.controller;

import com.pro.schedule.entity.Event;
import com.pro.schedule.service.EventService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
public class EventController {
    @Resource
    EventService eventService;

    @ApiOperation("获取当天事件")
    @PostMapping("/schedule/event/getList")
    public List<Event> getEventList(@RequestBody Event event, HttpServletRequest request) {
        String token = request.getHeader("Authorization");
        return eventService.getEventList(token, event.getEventDate());
    }

    @ApiOperation("获取当前事件")
    @PostMapping("/schedule/event/getInfo")
    public Event getEventInfo(HttpServletRequest request) {
        String token = request.getHeader("Authorization");
        return eventService.getEventInfo(token);
    }

    @ApiOperation("保存或修改事件")
    @PostMapping("/schedule/event/saveOrUpdate")
    public String saveOrUpdateEvent(@RequestBody Event event, HttpServletRequest request) throws Exception {
        String token = request.getHeader("Authorization");
        return eventService.saveOrUpdateEvent(token, event);
    }

    @ApiOperation("删除指定事件")
    @PostMapping("/schedule/event/delete")
    public String deleteEvent(@RequestBody Event event) throws Exception {
        return eventService.deleteEvent(event.getEventId());
    }

    @ApiOperation("清除当天事件")
    @PostMapping("/schedule/event/clear")
    public String clearEvent(@RequestBody Event event, HttpServletRequest request) throws Exception {
        String token = request.getHeader("Authorization");
        return eventService.clearEvent(token, event.getEventDate());
    }

    @ApiOperation("获取事件数量")
    @PostMapping("/schedule/event/getCount")
    public int getEventCount(HttpServletRequest request) {
        String token = request.getHeader("Authorization");
        return eventService.getEventCount(token);
    }
}
